package com.jp.knowledge.dialog;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.activity.BrowserActivity;
import com.jp.knowledge.activity.JpApplicationWebActivity;
import com.jp.knowledge.activity.WebBrowserActivity;

/**
 * Created by 528787067@qq.com on 2017/6/30.
 */

public class CopyrightDialog extends Dialog {

	private Context mContext;
	private View contentView;
	private View titleView;
	private View titleFrom;
	private TextView titleTag;
	private TextView titleText;
	private View openBtn;
	private TextView copyrightDesc;

	private String tag;
	private String title;
	private String openUrl;
	private String desc;

	public String getTag() {
		return tag;
	}

	public void setTag(String tag) {
		this.tag = tag;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getOpenUrl() {
		return openUrl;
	}

	public void setOpenUrl(String openUrl) {
		this.openUrl = openUrl;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public CopyrightDialog(Context context) {
		super(context, R.style.custom_idalgo);
		this.mContext = context;
		this.contentView = View.inflate(context, R.layout.dialog_copyright, null);
		setContentView(contentView);
		getWindow().setGravity(Gravity.BOTTOM);
		getWindow().getAttributes().width = context.getResources().getDisplayMetrics().widthPixels;

		titleView = contentView.findViewById(R.id.copyright_title_view);
		titleFrom = contentView.findViewById(R.id.copyright_title_view_from);
		titleTag = (TextView) contentView.findViewById(R.id.copyright_title_view_tag);
		titleText = (TextView) contentView.findViewById(R.id.copyright_title_view_title);
		openBtn = contentView.findViewById(R.id.copyright_title_view_open);
		copyrightDesc = (TextView) contentView.findViewById(R.id.copyright_desc);

		openBtn.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				dismiss();
				WebBrowserActivity.openWebActivity(mContext, openUrl);
			}
		});
	}

	@Override
	public void show() {
		if(TextUtils.isEmpty(tag)){
			titleTag.setVisibility(View.GONE);
		} else{
			titleTag.setVisibility(View.VISIBLE);
			titleTag.setText(tag);
		}
		titleText.setText(TextUtils.isEmpty(title) ? "" : title);
		if(TextUtils.isEmpty(tag) && TextUtils.isEmpty(title))
			titleFrom.setVisibility(View.GONE);
		else
			titleFrom.setVisibility(View.VISIBLE);
		openBtn.setVisibility(TextUtils.isEmpty(openUrl) ? View.GONE : View.VISIBLE);
		if(TextUtils.isEmpty(tag) && TextUtils.isEmpty(title) && TextUtils.isEmpty(openUrl))
			titleView.setVisibility(View.GONE);
		else
			titleView.setVisibility(View.VISIBLE);
		copyrightDesc.setText(TextUtils.isEmpty(desc) ? "" : desc);
		super.show();
	}
}
